package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbcDemo5 {
    public static void main(String[] args) {
        try(
        Connection connection = DBUtil.getConnection();
        ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.salary,t.title,c.name,c.floor\n" +
                    "FROM teacher t\n" +
                    "JOIN class c ON t.id = c.teacher_id\n" +
                    "WHERE t.name='王克晶'";
            System.out.println(sql);
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                int tId = rs.getInt(1);
                int tSalary = rs.getInt(2);
                String tTitle = rs.getString(3);
                String cName = rs.getString(4);
                int cFloor = rs.getInt(5);
                System.out.println(tId + " " + tSalary + " " + tTitle + " " + cName + " " + cFloor + " ");
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
